package com.mipo.core.utils;

import org.springframework.beans.factory.BeanNotOfRequiredTypeException;
import org.springframework.util.ClassUtils;

import java.util.Map;

/**
 * Created by cc on 2018/6/8.
 */
public class MapUtils {

    public static String getString(Map map,Object key) {
        return get(map,key,"",String.class);
    }


    public static Integer getInteger(Map map,Object key) {
        return get(map,key,0,Integer.class);
    }
    public static Long getLong(Map map,Object key) {
        return get(map,key,0,Long.class);
    }

    public static <T> T get(Map map,Object key,Class<T> requiredType) {
        return get(map,key,null,requiredType);
    }






    public static <T> T get(Map map,Object key,Object def, Class<T> requiredType) {



        Object keyValue = def;
        if (map.containsKey(key)) {
            keyValue = map.get(key);
        }

        if(requiredType != null && !requiredType.isAssignableFrom(keyValue.getClass())) {
            throw new RuntimeException("class type Exception");
        }
        return (T) keyValue;
    }

}
